#!/usr/bin/python

palette_flags = {
    'palettea': '-mR! -m! -gB4',  # this is 256 colour depth, without the T8 option
    'paletteb': '-mRt -gB8',  # this is 256 colour depth, without the T8 option
    'palettec': '-mR! -m! -gB4'
}
default_flags = '-mRt -gB4'
palettes = ['palette' + hex(i)[2] for i in xrange(0, 13)]
for palname in palettes:
    if palname in palette_flags:
        flags = palette_flags[palname]
    else:
        flags = default_flags
    flags += ' -ftc -q -gu16 -pS -O'+palname
    bld.transform_image(bld.glob(palname+'/*.pcx'), GRITFLAGS=flags)

pcx_files = bld.glob('palette*/*.pcx')
pcx_files += ['/'.join((p, p+'.c')) for p in palettes]
bld.new_task_gen(features='cc', target='pal_objects',
        source=[s.replace('.pcx', '.c') for s in pcx_files])
bld.new_task_gen(features='cc cstaticlib', target='pal',
        add_objects='pal_objects',
        includes=palettes, export_incdirs=palettes)
